<template>
  <div>
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive"></router-view>
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive"></router-view>
  </div>
</template>

<script>
import dingMixin from  '@/mixins/ding'
import * as dd from 'dingtalk-jsapi'
export default {
  mixins: [dingMixin],
  watch: {
    $route (to, from) {
      this.mobileSetTitle(to.meta.title);
      if(to.name === 'mbbs-article'){
        this.mobileHiddenRightMenu();
      }else if(to.name === 'mbbs-home' || to.name === 'mbbs-announcement' || to.name === 'mbbs-library' || to.name === 'mbbs-discussion' || to.name === 'mbbs-personal'){
        this.mobileSetRightMenu([{id: 'save', text: '写文章'}], (directive) => {
          if(directive === 'save'){
            this.$router.push({ name: 'mbbs-editor'})
          }
        });
      }
    }
  },
  mounted() {
    if(!this.isPC()) {
      this.$router.replace({ name: 'mbbs-home', params: {id: this.$route.query.articleId}})
      if (dd.env.platform!=="notInDingTalk") {
        this.getDingConfig().then(config =>{
          this.dingConfig = config;
          this.dingLogin(config.corpId, null);
          this.run_dd_config();
        })
      }
    }else {
      this.$router.replace({ name: 'bbs-home', params: {id: this.$route.query.articleId}})
    }
  }
}
</script>
